package com.chapter12.demo3;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;


/**
 * 12.6
 * 构造方法引用的格式为：类名：：new，
 * 对应的函数式接口中的方法需要有返回值，构造方法的参数列表要与接口中方法的参数列表一致。
 * Supplier<T>内置函数式接口
 */
public class ConstructorReference {
    public static void main(String[] args) {
        //无参构造方法
        Supplier<Student> s1 = Student::new;
        //等于
        Supplier<Student> s2 = ()->new Student();
        System.out.println(s1.get());

        //一个参数
        Function<Integer,Student> f1 = Student::new;
        //等于
        Function<Integer,Student> f2 =  (no)->new Student(no);
        System.out.println(f1.apply(1));
        System.out.println(f2.apply(100));

        //两个参数
        BiFunction<Integer,String,Student> b1 = Student::new;
        //等于
        BiFunction<Integer,String,Student> b2 =  (no,name)->new Student(no,name);
        System.out.println(b1.apply(2,"张三"));
        System.out.println(b2.apply(200,"李四"));
    }
}
